<%@page import="java.util.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<% String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="<%=basePath%>"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="css/backstyle.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="js/jquery.js"></script>

    <script type="text/javascript" src="js/productType.js"></script>
    <script type="text/javascript">
        $(function () {
            // 1.发送异步请求初始化大类
            initParentType();

            // 2.给pid绑定改变事件
            $("#pid").change(function () {

                // 获取选中的类别id
                var id = $(this).val();
                if (!id) {
                    alert("请选择大类");
                    return;
                }

                // 小类的元素
                var type2Ele = $("#type2");
                type2Ele.empty();   // 在初始化之前先删除原来的数据

                // 根据大类的id查询它的小类
                $.ajax({
                    url: "ProductTypeController/getProdctTypeListByPid?pid=" + id,
                    type: "GET",
                    dataType: "JSON",
                    success: function (data) {
                        type2Ele.append("<option value=''>==请选择==</option>");
                        $.each(data, function (index, item) {
                            var value = item.id;
                            var text = item.name;
                            var opEle = $(document.createElement("option")); // 把op(js)转成JQuery对象
                            opEle.val(item.id);
                            opEle.text(item.name);
                            type2Ele.append(opEle);
                        })
                    }
                });

            });
        })
    </script>
</head>

<body>

<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">表单</a></li>
    </ul>
</div>

<div class="formbody">

    <div class="formtitle"><span>添加商品信息</span></div>
    <!-- 表单中 -->
    <form method="post" enctype="multipart/form-data" action="ProductController/addProduct">
        <ul class="forminfo">
            <li><label>商品名称</label><input name="pname" value="爱疯14" type="text" class="dfinput"/><i>标题不能超过30个字符</i></li>
            <li><label>所属大类</label>
                <select name="type1" id="pid">
                    <option value="">==请选择==</option>
                </select>

            </li>
            <li><label>所属小类</label>
                <select name="type2" id="type2">
                    <option value="">==请选择==</option>
                </select>
            </li>
            <li><label>商品价格</label><input name="price" value="8999.9" type="text" class="dfinput"/></li>
            <li><label>商品库存</label><input name="stock" type="text" value="10" class="dfinput"/></li>
            <li><label>商品描述</label><textarea rows="8" cols="40" name="des">灵动岛xxxxxx</textarea></li>
            <li><label>商品图片</label><input name="pngUrl" type="file"/></li>
            <li><label>&nbsp;</label><input name="" type="submit" class="btn" value="确认保存"/></li>
        </ul>

    </form>
</div>
<div style="display:none">
    <script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script>
</div>
</body>
</html>

